//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace ViNoToolkit{

	/// <summary>
	/// Actor utility class.
	/// </summary>
	static public class ActorUtility {

		/// <summary>
		/// Sets up actor info.
		/// </summary>
		/// <param name="actor">Actor.</param>
		/// <param name="actorName">Actor name.</param>
		/// <param name="sizeInPercent">Size in percent.</param>
		/// <param name="nameTextColor">Name text color.</param>
		/// <param name="textures">Textures.</param>
        static public void SetUpActorInfo( ActorInfo actor , string actorName , float sizeInPercent , Color nameTextColor , Texture2D[] textures ){
            actor.actorName = actorName;
            actor.textColor = nameTextColor;

        	actor.baseActorState = new ActorInfo.ActorState();
        	actor.baseActorState.sizeInPercent = sizeInPercent;
            actor.baseActorState.dataArray = new SceneData.SceneNodeData[ textures.Length ];
            for( int i =0;i<textures.Length;i++){
                actor.baseActorState.dataArray[ i ] = new SceneData.SceneNodeData();
            	actor.baseActorState.dataArray[ i ].name = actorName + "_" + i.ToString();
                actor.baseActorState.dataArray[ i ].parentname = actorName;
                actor.baseActorState.dataArray[ i ].parentname = actorName;            
                actor.baseActorState.dataArray[ i ].alpha = 1f;
                actor.baseActorState.dataArray[ i ].posZ = - i;
                actor.baseActorState.dataArray[ i ].texturePath = textures[ i ].name;
            }
        }

		/// <summary>
		/// Sets up actor info.
		/// </summary>
		/// <param name="actor">Actor.</param>
		/// <param name="actorName">Actor name.</param>
		/// <param name="sizeInPercent">Size in percent.</param>
		/// <param name="nameTextColor">Name text color.</param>
		/// <param name="texturePaths">Texture paths.</param>
        static public void SetUpActorInfo( ActorInfo actor , string actorName , float sizeInPercent , Color nameTextColor , string[] texturePaths ){
            actor.actorName = actorName;
            actor.textColor = nameTextColor;
        	actor.baseActorState = new ActorInfo.ActorState();
        	actor.baseActorState.sizeInPercent = sizeInPercent;
            actor.baseActorState.dataArray = new SceneData.SceneNodeData[ texturePaths.Length ];
            for( int i =0;i<texturePaths.Length;i++){
                actor.baseActorState.dataArray[ i ] = new SceneData.SceneNodeData();
            	actor.baseActorState.dataArray[ i ].name = actorName + "_" + i.ToString();
                actor.baseActorState.dataArray[ i ].parentname = actorName;
                actor.baseActorState.dataArray[ i ].alpha = 1f;
                actor.baseActorState.dataArray[ i ].posZ = - i;
                actor.baseActorState.dataArray[ i ].texturePath = texturePaths[ i ];
            }
        }

		/// <summary>
		/// Sets up actor info.
		/// </summary>
		/// <param name="actor">Actor.</param>
		/// <param name="actorName">Actor name.</param>
		/// <param name="sizeInPercent">Size in percent.</param>
		/// <param name="nameTextColor">Name text color.</param>
		/// <param name="texturePaths">Texture paths.</param>
        static public void AddActorState( ActorInfo actor , string stateName , float sizeInPercent , string texturePath ){
//        	int addIndex = 0;
        	ActorInfo.ActorState actorState = null;
        	if( actor.actorStates == null ){
        		actor.actorStates = new ActorInfo.ActorState[ 1 ];
        		actor.actorStates[ 0 ] = new ActorInfo.ActorState();

        		actorState = actor.actorStates[ 0 ];
        	}
        	else{
	        	// Add ActorInfo to list buffer.
	        	List<ActorInfo.ActorState> list = new List<ActorInfo.ActorState>();

	        	int i=0;
	        	foreach( ActorInfo.ActorState state in actor.actorStates ){
	        		if( actor.actorStates[ i ].stateName == stateName ){
	        			break;
	        		}

	        		list.Add( state );
	        		i++;
	        	}

	        	actorState = new ActorInfo.ActorState() ;

	        	// Add State.
	        	list.Add( actorState );

        		actor.actorStates = list.ToArray();
//        		addIndex = list.Count - 1;
			}
			
        	actorState.stateName = stateName;
        	actorState.sizeInPercent = sizeInPercent;
           	actorState.dataArray = new SceneData.SceneNodeData[ 1 ];
            actorState.dataArray[ 0 ] = new SceneData.SceneNodeData();
        	actorState.dataArray[ 0 ].name = actor.actorName + "_0";
            actorState.dataArray[ 0 ].parentname = actor.actorName;
            actorState.dataArray[ 0 ].alpha = 1f;
//          actor.actorStates[ addIndex ].dataArray[ 0 ].posZ = 0;
            actorState.dataArray[ 0 ].texturePath = texturePath;
        }

		/// <summary>
		/// Gets the actor position from string like "center" , "left" , "middle_left" ...
		/// </summary>
		/// <returns>The actor position.</returns>
		/// <param name="position">Position.</param>
		static public SceneEvent.ActorPosition GetActorPosition( string position ){
			position = position.ToLower();
			SceneEvent.ActorPosition pos = SceneEvent.ActorPosition.center;		
			switch( position ){
				case "center":			pos = SceneEvent.ActorPosition.center;				break;
				case "left":			pos = SceneEvent.ActorPosition.left;				break;
				case "right":			pos = SceneEvent.ActorPosition.right;				break;
				case "middle_left":		pos = SceneEvent.ActorPosition.middle_left;		break;
				case "middle_right":	pos = SceneEvent.ActorPosition.middle_right;		break;
			}
			return pos;
		}								

	}

}